CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(myFramework)

IF(MSVC)
  ADD_DEFINITIONS(-D_USRDLL)
ENDIF(MSVC)

# Find out all source files
FILE(GLOB APP_HEADER "App/*.h")
FILE(GLOB APP_SRC "App/*.cpp")

IF(WIN32)
  FILE(GLOB_RECURSE APP_WIN32_HEADER ${PROJECT_SOURCE_DIR} "App/Windows/*.h")
  FILE(GLOB_RECURSE APP_WIN32_SRC ${PROJECT_SOURCE_DIR} "App/Windows/*.cpp")
ENDIF(WIN32)

IF(UNIX)
  ADD_DEFINITIONS(-DUSE_GUI_QT)
ENDIF(UNIX)

FILE(GLOB_RECURSE ENTITY_HEADER "Entity/*.h")
FILE(GLOB_RECURSE ENTITY_SRC "Entity/*.cpp")

FILE(GLOB GRAPHICS_HEADER "Graphics/*.h")
FILE(GLOB GRAPHICS_SRC "Graphics/*.cpp")

FILE(GLOB_RECURSE OPENGL_HEADER ${PROJECT_SOURCE_DIR} "Graphics/OpenGL/*.h")
FILE(GLOB_RECURSE OPENGL_SRC ${PROJECT_SOURCE_DIR} "Graphics/OpenGL/*.cpp")
FILE(GLOB_RECURSE OPENGL_C_SRC ${PROJECT_SOURCE_DIR} "Graphics/OpenGL/*.c")

FILE(GLOB_RECURSE PIPELINE_HEADER ${PROJECT_SOURCE_DIR} "Graphics/Pipeline/*.h")
FILE(GLOB_RECURSE PIPELINE_SRC ${PROJECT_SOURCE_DIR} "Graphics/Pipeline/*.cpp")

FILE(GLOB_RECURSE IMAGING_HEADER ${PROJECT_SOURCE_DIR} "Imaging/*.h")
FILE(GLOB_RECURSE IMAGING_SRC ${PROJECT_SOURCE_DIR} "Imaging/*.cpp")

FILE(GLOB_RECURSE UTILS_HEADER ${PROJECT_SOURCE_DIR} "Utils/*.h")
FILE(GLOB_RECURSE UTILS_SRC ${PROJECT_SOURCE_DIR} "Utils/*.cpp")

FILE(GLOB CONSOLE_HEADER "Console/*.h")
FILE(GLOB CONSOLE_SRC "Console/*.cpp")

FILE(GLOB COMMON_HEADER "./*.h")
FILE(GLOB COMMON_SRC "./*.cpp")

# setup groups for source file
SOURCE_GROUP("App" FILES ${APP_SRC} ${APP_HEADER})
IF(WIN32)
  SOURCE_GROUP("App\\Windows" FILES ${APP_WIN32_SRC} ${APP_WIN32_HEADER})
ENDIF(WIN32)

SOURCE_GROUP(Graphics FILES
  ${GRAPHICS_SRC} ${GRAPHICS_HEADER} ${GRAPHICS_C_SRC})
SOURCE_GROUP(Imaging FILES ${IMAGING_SRC} ${IMAGING_HEADER})
SOURCE_GROUP(Utils FILES ${UTILS_SRC} ${UTILS_HEADER})
SOURCE_GROUP(Common FILES ${COMMON_SRC} ${COMMON_HEADER})
SOURCE_GROUP("Graphics\\OpenGL" FILES
  ${OPENGL_C_SRC} ${OPENGL_HEADER} ${OPENGL_SRC})
SOURCE_GROUP("Graphics\\Pipeline" FILES
  ${PIPELINE_SRC} ${PIPELINE_HEADER})
SOURCE_GROUP(Mesh FILES ${MESH_SRC} ${MESH_HEADER})
SOURCE_GROUP(Entity FILES ${ENTITY_SRC} ${ENTITY_HEADER})
SOURCE_GROUP(Console FILES ${CONSOLE_HEADER} ${CONSOLE_SRC})

ADD_DEFINITIONS(-DILUT_USE_OPENGL
  -DLIBFRAMEWORK_EXPORTS
  -DGLEW_BUILD
  -DCRT_SECURE_NO_WARNINGS)

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/../../Dependencies/Include)
INCLUDE_DIRECTORIES(.)

LINK_DIRECTORIES(${launcher_SOURCE_DIR}/../../Dependencies/Lib)

# Setup sources to compile
SET(FrameSources
  ${APP_SRC} ${APP_HEADER}
  ${APP_WIN32_SRC} ${APP_WIN32_HEADER}
  ${CONSOLE_SRC} ${CONSOLE_HEADER}
  ${GRAPHICS_SRC} ${GRAPHICS_HEADER}
  ${OPENGL_SRC} ${OPENGL_HEADER} ${OPENGL_C_SRC}
  ${PIPELINE_SRC} ${PIPELINE_HEADER}
  ${IMAGING_SRC} ${IMAGING_HEADER}
  ${UTILS_SRC} ${UTILS_HEADER}
  ${COMMON_SRC} ${COMMON_HEADER}
  ${MESH_SRC} ${MESH_HEADER}
  ${ENTITY_SRC} ${ENTITY_HEADER})

# Setup libraries to link
SET(FrameLibraries freeimage Cg CgGL)

IF(WIN32)
  LIST(APPEND FrameLibraries cgD3D9)
ENDIF(WIN32)

IF(LINUX)
  LIST(APPEND FrameLibraries GLU)
ENDIF(LINUX)

ADD_LIBRARY(myframework SHARED ${FrameSources})

# Link myFramework against freeimage
TARGET_LINK_LIBRARIES(myframework ${FrameLibraries})

SET(EXECUTABLE_OUTPUT_PATH ${GLOBAL_OUTPUT_PATH})
SET(LIBRARY_OUTPUT_PATH ${GLOBAL_OUTPUT_PATH})

IF(MSVC)
  SET_TARGET_PROPERTIES(myframework PROPERTIES PREFIX "../")
  SET_TARGET_PROPERTIES(myframework PROPERTIES IMPORT_PREFIX "../")
ENDIF(MSVC)
